package org.goochasca

private[goochasca] trait GridLines extends Chart {

  private val Formatter = "%.2f"

  private var columns = 0
  private var rows = 0
    
  /**
   * Divide chart into rows and columns.
   * @param columns Number of columns to divide the x-axis into
   * @param rows Number of rows to divide the y-axis into
   */
  def setGrid(columns: Int, rows: Int) {
    this.columns = columns
    this.rows = rows
  }
  
  override protected def appendParms(sb: StringBuilder) {
    super.appendParms(sb)
    val x = if (columns > 0) 100f/columns else 0f
    val y = if (rows > 0) 100f/rows else 0f
    if (x > 0f || rows > 0f) {
      sb append "&chg=" append Formatter.format(x) append ',' append Formatter.format(y)
    }
  }
}
